#ifndef RECURSION_H
#define RECURSION_H

#include "stdfax.h"
#include "storage.h"

typedef struct 
{

	request_node_ht req_ht;
	unsigned char tempbuffer[2048];

}recursion_server;

typedef struct
{
	int len;
	int cap;
	request_node** nodes;
	pthread_mutex_t _lock;
}rnode_event;

extern recursion_server RS_SERVER;



int update_event(int afd, dns_info_t* q, unsigned char *sndbuf, int sndlen);


void update(int afd, dns_info_t* q, request_node* rnode, unsigned char *sndbuf, int sndlen, rnode_event *rnodes);

inline table_t* get_rnodes();

request_node* generate_request_node(request_info* pinfo);
void free_request(request_info* pinfo);
int query_from_auth_server(request_node *pnode, unsigned char *sndbuf, int sndlen, struct sockaddr_in *aaddr);

int resp_to_client(request_node* rnode, unsigned char* rname, mvalue_t *mv, unsigned char *sndbuf, int sndlen);





request_node*  add_rnode(request_info* rinfo, packet_type*lowerdomain);
dns_info_t* create_query(unsigned char *qname, unsigned int qtype, unsigned char *sendbuf, unsigned int sendlen);


int query_from_auth_server_dnspod(request_info *pinfo, unsigned char *sndbuf, int sndlen, struct sockaddr_in *aaddr);


#endif